#include "stack.h"
#include <assert.h>

void stack_init(stack_node * stack)
{
    stack->len = 0;
    list_init(&stack->entries);
}

void stack_push(stack_node * stack, struct entry * entry)
{
    list_add(&stack->entries, &entry->node);
    stack->len++;
}

struct entry * stack_pop(stack_node * stack)
{
    assert(stack->len - 1 >= 0);

    struct entry * res = LIST_ENTRY(stack->entries.next, struct entry);
    list_del(stack->entries.next);
    stack->len--;

    return res;
}
